/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.gemom.gui;

import com.gemom.util.*;
import com.gemom.combinationItems.*;
import com.gemom.auction.*;
import com.gemom.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

/**
 *
 * @author Yair Diaz
 */

//NewJPanel2.java is the version improved
public class Page2Panel extends JPanel {

    private double[][] seriesData;
    private Item[] itemsArray;
    private GBroker[] gBrokersArray;
    private double[] itemsRevenueFactor;
    
 
    CovMatrixData covM;
    JPanel topPanel,nPanel;
    int numberbrokers;
    
     Vector<Bid> listBids;
     searchTree2 tree;
    
    
    public Page2Panel(int numberitems)
    {
       // this.numberbrokers=numberbroke;
   
        topPanel = new JPanel(new GridBagLayout()); 
        GridBagConstraints c = new GridBagConstraints();
        Insets inset=new Insets(5,5,5,5);
	c.insets = inset;
        c.gridwidth = 1;c.gridheight = 1;
        c.gridx=0; c.gridy=0;

       // oneBrokerPanel onebp= new oneBrokerPanel(1);
       // topPanel.add(onebp);

        topPanel.setBackground(Color.WHITE);
        this.setLayout(new BorderLayout());
        this.add(BorderLayout.NORTH,topPanel);
        this.setBackground(Color.WHITE);
        this.setSize(1225,767);
    }
    
    //initialisation of seriesData,seriesDataRevenue,itemsArray and itemsRevenueFactor
    public void setSeriesInfo(double[][] seriesData,CovMatrixData covM)
    {   //rows:samples  columns:series
        this.seriesData=seriesData;
        this.covM=covM;
        
        //generates itemsRevenueFactor
        this.itemsRevenueFactor=new double[this.seriesData[0].length];
        double factor=0;
        for(int i=0;i<this.seriesData[0].length;i++)
        {   factor= 1.0 + 0.2 * Math.random();
            this.itemsRevenueFactor[i]=factor;
        }
        
        //generation of the item objects
        this.itemsArray=new Item[this.seriesData[0].length];
        for(int i=0;i<this.seriesData[0].length;i++)
        {
          this.itemsArray[i]= new Item(i,this.covM.getMeanAndStdDev()[0][i],
                                    this.covM.getMeanAndStdDev()[1][i],this.itemsRevenueFactor[i]);
        }
        
        //Generating the GBrokers: capacity between 50 and 70 
        //but can be modified at request
        double factor2=0;
        this.gBrokersArray=new GBroker[numberbrokers];
           for(int i=0;i<this.gBrokersArray.length;i++)
           {   factor2= 50.0 + 20.0;///* Math.random();////////////////////////
               this.gBrokersArray[i]= new GBroker(i,factor2);
           }
                
       
          
     //   BidGene bidin  = new BidGene(itemsArray,gBrokersArray,this.covM);
        
    //     listBids = bidin.getlistBids();
        
        
        
        System.out.println(new Date());
        
        
        
        
	
        
        
         new Thread(new Runnable() {  public void run() {
                
        tree = new searchTree2(listBids,0.95);
                 
        System.out.println("The winner path is:A*star");
	for(int i=0;i<tree.getWinnerPath().size();i++)
		System.out.println(tree.getWinnerPath().get(i));
	System.out.println("The max path value is: "+tree.getTotalWinnerPath());
        System.out.println("Number of nodes explored: "+tree.getNodesExplored());
	System.out.println(new Date());
                 
                 
                 
                 
            
                            }  }).start(); // start the thread
        
        

        
        
      //  covmatrixGUI2.enterCovMatrixData(covMRev.getCovMatrix());
        
        /*
        for(int i=0;i<itemsArray.length;i++)
        {
            System.out.println("rate "+itemsArray[i].getItemRate());
            System.out.println("rev "+itemsArray[i].getRevenueItem());
            System.out.println("fact "+itemsArray[i].getRevenueFactor());
            
        }
       */ 
  
    }


    
    
    
}
